********************************************************
*Replication do-file for Leighley & Oser "Representation in an Era…"
********************************************************
*Software: Analysis conducted in stata 14
*Data: all dta files for CCES downloaded from CCES dataverse (https://cces.gov.harvard.edu/data).

/*TABLE OF CONTENTS 
*SECTION 1: CREATE HOUSE DTA FILES 
*SECTION 2: JOIN & RECODE PART 1: ACA, KEYSTONE, KFTA 
*SECTION 3: RECODE PART 2 - CONFLICT DISTRICT CODE & JOIN DADT
*SECTION 4: ANALYSIS DOCUMENTATION
*/

***********************************
*SECTION 1: CREATE HOUSE DTA FILES 
***********************************


/* HOUSE: MATCH ON STATE (STRING), THEN DISTRICT (NUMERIC)
use "house_votes_112cong_2012cces.dta", replace
tostring district, replace
gen st_dist=state+"_"+district
sort st_dist, stable
by st_dist: gen counter=_n 
reshape wide name party district healthcarerepeal1 ryanbudget colombiafreetrade  ///
	panamafreetrade koreafreetrade simpsonbowles keystonepipeline ///
	healthcarerepeal2, i(st_dist) j(counter) 
foreach var of varlist *1 {
		local n=substr("`var'",1,length("`var'")-1)+"_House1"
		rename `var' `n'
		}
foreach var of varlist *2 {
		local n=substr("`var'",1,length("`var'")-1)+"_House2"
		rename `var' `n'
		}		
drop state
split st_dist, p("_")
rename st_dist1 state
rename st_dist2 district
drop st_*
replace state=trim(state)
replace district=trim(district)

foreach var of varlist *1 {
	local n=substr("`var'",1,length("`var'")-1)+"2"
	replace `var'=`n' if `var'==""
	}
drop *2
sort state district
save house, replace
*/


*********************************************************
*SECTION 2: JOIN & RECODE PART 1: ACA, KEYSTONE, KFTA 
*********************************************************

***
*JOIN FILES
***
/*
use "CCES12_Common_VV.dta", replace
gen district=trim(cdid)
gen state=trim(StateAbbr)

sort state district, stable
merge m:1 state district using house
drop _merge

*SAMPLE IDENTIFIERS:
*codebook V101 V103 cdid cdid113 countyfips

****
*CODING RESPONDENT SOCIO-DEM DATA for controls, "Profile survey"
****
set more off
tab birthyr, miss
gen age=2012-birthyr
label var age "Respondent Age"
sum age
tab gender, miss
tab gender, miss nolab
tab educ, miss
tab educ, miss nolab

* race - small N in some categories, make AfAm, Hispanic, other non-white dummies
tab race, miss
tab race, miss nolab
gen afam=race==2
replace afam=. if missing(race)
label variable afam "Race: African American Dummy"

gen hisp=race==3
replace hisp=. if missing(race)
label variable hisp "Race: Hispanic Dummy"

gen other=race>3
replace other=. if missing(race)
label variable other "Race: Other Non-White Race"


*different pid options:
tab pid7, miss
tab pid7, miss nolab
tab pid3, miss 
tab pid3, miss nolab
tab pid7others, miss
tab pid7others, miss nolab

*Family income
tab faminc, miss
tab faminc, miss nolab

*Recoding faminc
tab faminc, miss
tab faminc, miss nolab
recode faminc (97=.), gen (faminc_)
tab faminc_, miss

****
*POST-ELECTION SURVEY 
****

*Did you vote?
tab CC401, miss
tab CC401, nolab

gen vote=CC401==5
replace vote=. if CC401==.
tab vote CC401, miss
tab vote, miss
tab vote, miss nolab

tab votereg_post, miss
tab votereg_post, miss nolab


*Cleaning vote variable so that those who responded "no" or "don't know" to "Voter registration status"
*Are listed as "no" instead of "missing"
clonevar vote_ = vote
replace vote_=0 if votereg_post==2 & vote ==.
replace vote_=0 if votereg_post==3 & vote ==.
tab vote_ votereg_post, miss
label define vote_ 0 "No" 1 "Yes"
label values vote_ vote_
tab vote vote_, miss
tab vote_, miss
tab vote_, miss nolab
tab vote_


*****************************************
*Vote - recoding with catalist variables
*****************************************

*Whether a catalist administrative match is made - yes or no (doesn't yet inform us re: voting practice)
tab catalist_match, miss  /* 9,314 unmatched cases, 17.08% of data file */

*How much does this catalist administrative match overlap with missing data in CCES
*Crosstabs between catalist match & recoded vote var
tab catalist_match vote_, miss
tab catalist_match vote_, miss nolab

*Creating correctly coded validated vote variable
clonevar vote_v = vote_
replace vote_v = . if catalist_match==0 & vote_ == 1
*This recode means the 5,031 cases who self-reported "yes" as voters, but were unsuccessful admin matches for catalist become "missing"
*But we retain as "no" the 1,736 respondents who self-reported as non-voters, even though they were unsuccessful admin matches for catalist

tab voter_status, miss

*Recoding catalist general vote var as string, then "0" and "1"
tab e2012g, miss
tab e2012g catalist_match, miss
tab e2012g, miss nolab
encode e2012g, generate(e2012g_)
tab e2012g_, miss nolab
recode e2012g_ (1/3=1) (4=0) (5/6=1)
label values e2012g_ vote_
tab e2012g_ e2012g, miss
tab e2012g_, miss
tab e2012g_

tab e2012g_ vote_v, miss
clonevar vote_v2 = e2012g_
tab vote_v2
replace vote_v2=0 if vote_v==0 & e2012g_==.
tab vote_v2 e2012g_, miss
tab vote_v2, miss
tab vote_v2

label var vote_ "Self-reported Vote"
label var vote_v2 "Validated Vote"
tab vote_v2 vote_, miss

*Tab of finally coded voting vars:
tab vote_, miss
tab vote_
tab vote_v2, miss
tab vote_v2


****
*Political engagement indicators
****
*Attend local political meetings
tab CC417a_1, miss
tab CC417a_1, miss nolab

*Put up political sign
tab CC417a_2, miss

*Work for candidate or campaign
tab CC417a_3, miss

*Made political donation (yes/no)
tab CC417a_4, miss
tab CC417a_4, miss nolab


**PID

*Generally speaking, do you think of yourself as a....Dem, Rep, Ind, Other open textbox (pid3_t), Not Sure [p.35 of cces guide from June 2015]
tab pid3, miss 


* CREATE CLEAN PID VARIABLE TO MAKE INDEP REFERENCE CATEGORY
tab pid3, miss
tab pid3, miss nolab
gen pid_r=pid3
replace pid_r=. if pid3>3
replace pid_r=4-pid_r
label define pid 1 "Ind" 2 "Rep" 3 "Dem"
label values pid_r pid
label var pid_r "Recoded 3-Category Party Identification"
tab pid3 pid_r, miss
tab pid_r, miss

* CREATE VAR FOR CO-PARTISANSHIP
tab party_House1, miss
gen copartisan=(pid_r==3 & substr(trim(party_House1),1,1)=="D") | (pid_r==2 & substr(trim(party_House1),1,1)=="R")
sort party_House1
by party_House1: tab pid_r copartisan
tab copartisan, miss
tab copartisan pid_r, miss
clonevar copartisan_ = copartisan
replace copartisan_ = . if missing(pid_r)
tab copartisan_, miss


****
*RESPONDENT ROLL-CALL VOTE POLICY PREFERENCE, ISSUES USED IN ANALYSIS 
****
*Prefatory question documented in CCES Guide:
*"Congress considered many important bills over the past two years. 
*For each of the following tell us whether you support or oppose the legislation in principle"

*US-Korea Free trade agreement
tab CC332F, miss

*Repeal affordable care act
tab CC332G, miss
*question: "Would repeal the affordable care act"
*i.e., "support" = repeal ACA // "oppose" = leave ACA as is.

*Keystone pipeline
tab CC332H, miss

*End don't ask don't tell
tab CC332J, miss

*Documenting tabs for relevant issues for our analysis
tab1 CC332F CC332G CC332H CC332J, miss


******Recoding policy opinion vars to prep for participators/non-participators means on policy opinion & congruence 

*US-Korea Free trade agreement
tab CC332F, miss
tab CC332F, miss nolab
clonevar koreafta = CC332F
replace koreafta = 2 - koreafta
tab koreafta, miss
tab koreafta, miss nolab

*Repeal affordable care act
tab CC332G, miss
tab CC332G, miss nolab
clonevar aca1 = CC332G
replace aca1 = 2 - aca1
tab aca1, miss
tab aca1, miss nolab

*Keystone pipeline
tab CC332H, miss
tab CC332H, miss nolab
clonevar keystone = CC332H
replace keystone = 2 - keystone
tab keystone, miss
tab keystone, miss nolab

label define policies 0 "Oppose" 1 "Support"
label values koreafta keystone aca1 policies
tab1 koreafta keystone aca1, miss


keep V101 V103 cdid cdid113 countyfips age gender educ race pid* faminc afam hisp other district ///
CC417* CC332F CC332G CC332H CC332J state ///
healthcarerepeal2_House1 ///
copartisan vote vote_ vote_v2 faminc_  ///
healthcarerepeal1_House1 koreafreetrade_House1 keystonepipeline_House1 ///
koreafta keystone aca1 


***
* GENERATE HOUSE AGREEMENT QUESTIONS
***

tab healthcarerepeal1_House1, missing
gen H_acarepeal1=(trim(healthcarerepeal1_House1)=="For" & CC332G==1) | (trim(healthcarerepeal1_House1)=="Against" & CC332G==2) 
replace H_acarepeal1=. if trim(healthcarerepeal1_House1)=="Did Not Vote" | trim(healthcarerepeal1_House1)=="" | ///
	CC332G==.
label var H_acarepeal1 "Agrees with Rep: Repeal ACA 1"
*NOTE: "2" for respondents mean that you Oppose the Repeal, i.e. that you support the ACA act

tab koreafreetrade_House1, missing
gen H_koreafta=(trim(koreafreetrade_House1)=="For" & CC332F==1) | (trim(koreafreetrade_House1)=="Against" & CC332F==2) 
replace H_koreafta=. if trim(koreafreetrade_House1)=="Did Not Vote" | trim(koreafreetrade_House1)=="" | ///  
	CC332F==.
label var H_koreafta "Agrees with Rep: Korea Free Trade"

tab keystonepipeline_House1, missing
gen H_keystone=(trim(keystonepipeline_House1)=="For" & CC332H==1) | (trim(keystonepipeline_House1)=="Against" & CC332H==2) 
replace H_keystone=. if trim(keystonepipeline_House1)=="Did Not Vote" | trim(keystonepipeline_House1)=="" | ///  
	CC332H==.
label var H_keystone "Agrees with Rep: Keystone"

label define agree 0 "Disagrees with Representative" 1 "Agrees with Representative"
label values H_* agree

tab1 H_koreafta H_keystone H_acarepeal1, miss


* REVERSE CODE ACTIVITIES
tab CC417a_1, miss
tab CC417a_1, miss nolab /* Yes = 1; No = 2*/
replace CC417a_1=2-CC417a_1
replace CC417a_2=2-CC417a_2
replace CC417a_3=2-CC417a_3
replace CC417a_4=2-CC417a_4
label define activities 0 "No" 1 "Yes"
label values CC417a_1 CC417a_2 CC417a_3 CC417a_4 activities
tab1 CC417a_1 CC417a_2 CC417a_3 CC417a_4, miss

*Recode, version with descriptive names
clonevar mtgs = CC417a_1
tab mtgs, miss
clonevar sign = CC417a_2
tab sign, miss
clonevar campaign = CC417a_3
tab campaign, miss
clonevar donate = CC417a_4
tab donate, miss

mean mtgs sign campaign donate vote_ vote_v2 
svyset [pweight = V103]
mean mtgs sign campaign donate vote_ vote_v2 

corr mtgs sign campaign donate vote_v2
svyset [pweight = V103]
corr mtgs sign campaign donate vote_v2

*Creating "Non-voting activities" variable:
clonevar polact3 = sign
replace polact3 = 1 if mtgs == 1
replace polact3 = 1 if campaign == 1
tab polact3, miss
label define polact3 0 "Not active" 1 "Active 1+"
label val polact3 polact3
label var polact3 "Dichotomize Activities 3"
tab polact3 campaign, miss
tab polact3 mtgs, miss
tab polact3 sign, miss
tab polact3, miss

* CREATE CLUSTER VARIABLE
gen st_dist=state+district

* SAVE
save recoded_CCES2012, replace

*/



*********************************************************			 
*SECTION 3: RECODE PART 2 - CONFLICT DISTRICT CODE & JOIN DADT
*********************************************************
/*
***
*A: CONFLICT DISTRICT INDICATORS 
***


use recoded_CCES2012.dta, replace

save recoded2_CCES2012.dta, replace

set more off
foreach var of varlist polact3 vote_v2 donate {

	collapse CC332? [pweight=V103], by(st_dist `var')
	drop if `var'==.
	reshape wide CC332?, i(st_dist) j(`var')

	foreach l in "F" "G" "H" "J" {

		gen nconflict`var'`l'=((CC332`l'0>1.5 & CC332`l'1<1.5) | (CC332`l'0<1.5 & CC332`l'1>1.5)) 
		lab var nconflict`var'`l' "Conflict District no sd by `val' for Issue `l'"
	}

	drop CC*

	label def conf 0 "No Conflict" 1 "Conflict District"
	label val nconflict`var'`l'* conf

	sort st_dist, stable

	save temp_conflict, replace

	use recoded2_CCES2012.dta, replace
	sort st_dist, stable

	merge m:1 st_dist using temp_conflict
	drop _merge

	save recoded2_CCES2012.dta, replace
}



*Documenting conflict district proportions, by respondent & by district:

**polact3
use recoded2_CCES2012.dta, replace
set more off
tab1 nconflictpolact3?
collapse CC332?, by(st_dist nconflictpolact3?)
tab1 nconflictpolact3?

**vote_v2
use recoded2_CCES2012.dta, replace
set more off
tab1 nconflictvote_v2?
collapse CC332?, by(st_dist nconflictvote_v2?)
tab1 nconflictvote_v2?

**donate
use recoded2_CCES2012.dta, replace
set more off
tab1 nconflictdonate?
collapse CC332?, by(st_dist nconflictdonate?)
tab1 nconflictdonate?



**************
*JOIN DADT
************* 
use recoded2_CCES2012.dta, replace


* Need to label states for effective merge, which requires Cuevas_2012-House-Candidates-by-Race.dta file with state labels

use 2012RollCalls.dta, replace
keep inputstate cdid rollcall_J
sort inputstate cdid, stable

tempfile new_roll_call
save "`new_roll_call'"

use "Cuevas_2012-House-Candidates-by-Race.dta", replace
keep inputstate state
duplicates drop
replace state=proper(state)
sort inputstate, stable

merge 1:m inputstate using "`new_roll_call'", nogen

replace state="AL" if state=="Alabama"
replace state="AK" if state=="Alaska"
replace state="AZ" if state=="Arizona"
replace state="AR" if state=="Arkansas"
replace state="CA" if state=="California"
replace state="CO" if state=="Colorado"
replace state="CT" if state=="Connecticut"
replace state="DE" if state=="Delaware"
replace state="DC" if state=="Dist. of Columbia"
replace state="FL" if state=="Florida"
replace state="GA" if state=="Georgia"
replace state="HI" if state=="Hawaii"
replace state="ID" if state=="Idaho"
replace state="IL" if state=="Illinois"
replace state="IN" if state=="Indiana"
replace state="IA" if state=="Iowa"
replace state="KS" if state=="Kansas"
replace state="KY" if state=="Kentucky"
replace state="LA" if state=="Louisiana"
replace state="ME" if state=="Maine"
replace state="MD" if state=="Maryland"
replace state="MA" if state=="Massachusetts"
replace state="MI" if state=="Michigan"
replace state="MN" if state=="Minnesota"
replace state="MS" if state=="Mississippi"
replace state="MO" if state=="Missouri"
replace state="MT" if state=="Montana"
replace state="NE" if state=="Nebraska"
replace state="NV" if state=="Nevada"
replace state="NH" if state=="New Hampshire"
replace state="NJ" if state=="New Jersey"
replace state="NM" if state=="New Mexico"
replace state="NY" if state=="New York"
replace state="NC" if state=="North Carolina"
replace state="ND" if state=="North Dakota"
replace state="MP" if state=="Northern Marianas"
replace state="OH" if state=="Ohio"
replace state="OK" if state=="Oklahoma"
replace state="OR" if state=="Oregon"
replace state="PA" if state=="Pennsylvaina"
replace state="PA" if state=="Pennsylvania"
replace state="RI" if state=="Rhode Island"
replace state="SC" if state=="South Carolina"
replace state="SD" if state=="South Dakota"
replace state="TN" if state=="Tennessee"
replace state="TX" if state=="Texas"
replace state="UT" if state=="Utah"
replace state="VT" if state=="Vermont"
replace state="VA" if state=="Virginia"
replace state="WA" if state=="Washington"
replace state="WV" if state=="West Virginia"
replace state="WI" if state=="Wisconsin"
replace state="WY" if state=="Wyoming"

gen st_dist=state+cdid

sort st_dist, stable
tempfile states
save "`states'"

use recoded2_CCES2012, replace
sort st_dist, stable

merge m:1 st_dist using "`states'"
drop if _merge==2
drop _merge

rename rollcall_J dontaskdonttell_House1
order dontaskdonttell_House1, after(healthcarerepeal2_House1) 
order st_dist, first

* Create congruence
gen H_dontask=.
replace H_dontask=1 if CC332J==1 & inlist(trim(dontaskdonttell_House1),"Announced For","Yea")
replace H_dontask=1 if CC332J==2 & inlist(trim(dontaskdonttell_House1),"Announced Against","Nay")
replace H_dontask=0 if CC332J==2 & inlist(trim(dontaskdonttell_House1),"Announced For","Yea")
replace H_dontask=0 if CC332J==1 & inlist(trim(dontaskdonttell_House1),"Announced Against","Nay")
label values H_dontask agree
label var H_dontask "Agrees with Rep: Don't Ask Don't Tell"

* Check Coding
tab H_dontask
tab H_dontask dontaskdonttell_House1 if CC332J==1
tab H_dontask dontaskdonttell_House1 if CC332J==2

save CCES2012_foranalysis, replace
*/

****




********************************************
*SECTION 4: ANALYSIS DOCUMENTATION
********************************************
/*
*DATA:
use  CCES2012_foranalysis.dta, replace
set more off

*Review of Main variables of interest for analysis:
*POLICY CONGRUENCE /*followed by CCES var name for original respondent var*/
tab H_koreafta, miss /* CC332F */
tab H_acarepeal1, miss /* CC332G */
tab H_keystone, miss /* CC332H */
tab H_dontask, miss /*CC332J */
tab1 H_koreafta H_acarepeal1 H_keystone H_dontask, miss

*PARTICIPATION VARIABLES:
tab vote_v2, miss /*Validated vote in last ntl election*/
*Checking that recoded descriptive name versions of these variables are correctly coded (yes):
tab mtgs CC417a_1, miss
tab sign CC417a_2, miss
tab campaign CC417a_3, miss
tab polact3, miss /*political activism dichotomous variable = 0 if nothing, 1 if any of "mtgs" "sign" or "campaign" */
*Donate, question in battery of "political activities"
tab donate CC417a_4, miss


*CONFLICT DISTRICTS VARIABLES, for each relevant issue for following participation variables:
**vote_v2 (national vote, validated) 
tab nconflictvote_v2F, miss
tab nconflictvote_v2G, miss
tab nconflictvote_v2H, miss
tab nconflictvote_v2J, miss
**polact3 ("One or More Activities" (sign mtg campaign))
tab nconflictpolact3F, miss
tab nconflictpolact3G, miss
tab nconflictpolact3H, miss
tab nconflictpolact3J, miss
**donate (pol donate in past year, y/n)
tab nconflictdonateF, miss
tab nconflictdonateG, miss
tab nconflictdonateH, miss
tab nconflictdonateJ, miss

*Control vars for regression
tab educ, miss 
sum age, detail
tab gender, miss
tab pid_r, miss
tab afam, miss
tab hisp, miss
tab other, miss
tab faminc_, miss

*New var coding:
*Income, recoding as centered log for interaction
xtile faminc_3 = faminc_, nquantiles(3)	
gen cent_log_income=log(faminc_)
quietly sum cent_log_income
local m=r(mean)
replace cent_log_income=cent_log_income-`m'
label var cent_log_income "Centered log of recoded family income"

****************
*****TABLES*****
****************

**********************************************
*TABLE 1: Policy opinion and support, by issue

svyset st_dist [pweight=V103]
set more off

gen congruenceF = H_koreafta 
gen congruenceG = H_acarepeal1 
gen congruenceH = H_keystone 	 
gen congruenceJ = H_dontask 
label define agree2 0 "Disagrees" 1 "Agrees"
label values congruence? agree2
	
local policies "F G H J"
foreach l of local policies {
	
	svy, subpop(nconflictvote_v2`l'): proportion congruence`l', over(vote_v2)
	lincom _b[Agrees:Yes]-_b[Agrees:No]
	
	svy, subpop(nconflictdonate`l'): proportion congruence`l', over(donate) 
	lincom _b[Agrees:Yes]-_b[Agrees:No]	
	
	svy, subpop(nconflictpolact3`l'): proportion congruence`l', over(polact3) 
	lincom _b[Agrees:_subpop_1]-_b[Agrees:_subpop_2]
}

drop congruence?
**************************************
*TABLE 2 
***ACA REPEAL
estimates clear
logit H_acarepeal1 vote_v2 if nconflictvote_v2G==1 [pweight=V103], cluster(st_dist)
eststo
logit H_acarepeal1 vote_v2##copartisan if nconflictvote_v2G==1 [pweight=V103], cluster(st_dist)
eststo
*margins vote_v2##copartisan
*marginsplot, ytitle("Pr(Congruence)")
*Fig1A_Voting
***KEYSTONE
logit H_keystone vote_v2 if nconflictvote_v2H==1 [pweight=V103], cluster(st_dist)
eststo
logit H_keystone vote_v2##copartisan if nconflictvote_v2H==1 [pweight=V103], cluster(st_dist)
eststo
***DADT
logit H_dontask vote_v2 if nconflictvote_v2J==1 [pweight=V103], cluster(st_dist)
eststo
logit H_dontask vote_v2##copartisan if nconflictvote_v2J==1 [pweight=V103], cluster(st_dist)
eststo
***KFTA
logit H_koreafta vote_v2 if nconflictvote_v2F==1 [pweight=V103], cluster(st_dist)
eststo
logit H_koreafta vote_v2##copartisan if nconflictvote_v2F==1 [pweight=V103], cluster(st_dist)
eststo
esttab using Table2.rtf, b(3) se(3) ar2 label title (Simple Models of Policy Congruence) ///
	mtitles("Model 1" "Model 2" "Model 1" "Model 2" "Model 1" "Model 2" "Model 1" "Model 2") ///
	drop(0.vote_v2 0.copartisan 0.vote_v2#0.copartisan 0.vote_v2#1.copartisan 1.vote_v2#0.copartisan) ///
	nogap replace

**************************************
*TABLE 3 
***ACA REPEAL***
eststo clear
*Donate
logit H_acarepeal1 donate if nconflictdonateG==1 [pweight=V103], cluster(st_dist)
eststo
logit H_acarepeal1 donate##copartisan if nconflictdonateG==1 [pweight=V103], cluster(st_dist)
eststo
*Figure 1B_Donate
*margins donate##copartisan
*marginsplot, ytitle("Pr(Congruence)")
*Activity3
logit H_acarepeal1 polact3 if nconflictpolact3G==1 [pweight=V103], cluster(st_dist)
eststo
logit H_acarepeal1 polact3##copartisan if nconflictpolact3G==1 [pweight=V103], cluster(st_dist)
eststo
*Figure1C_polact3
*margins polact3##copartisan
*marginsplot, ytitle("Pr(Congruence)")
***KEYSTONE***
*Donate
logit H_keystone donate if nconflictdonateH==1 [pweight=V103], cluster(st_dist)
eststo
logit H_keystone donate##copartisan if nconflictdonateH==1 [pweight=V103], cluster(st_dist)
eststo
*Activity3
logit H_keystone polact3 if nconflictpolact3H==1 [pweight=V103], cluster(st_dist)
eststo
logit H_keystone polact3##copartisan if nconflictpolact3H==1 [pweight=V103], cluster(st_dist)
eststo
esttab using Table3.rtf, b(3) se(3) ar2 label title (T3 ACA & Keystone) ///
	mtitles("Model 1" "Model 2" "Model 3" "Model 4" "Model 1" "Model 2" "Model 3" "Model 4") ///
	drop(0.donate 0.copartisan 0.donate#0.copartisan 0.donate#1.copartisan 1.donate#0.copartisan ///
	     0.polact3 0.copartisan 0.polact3#0.copartisan 0.polact3#1.copartisan 1.polact3#0.copartisan) ///
	nogap replace

****************************
* TABLE 4 
use CCES2012_foranalysis.dta, replace
xtile faminc_3 = faminc_, nquantiles(3)
svyset st_dist [pweight=V103]
gen congruenceG = H_acarepeal1 
label define agree2 0 "Disagrees" 1 "Agrees"
label values congruenceG agree2
svy, subpop(nconflictvote_v2G): proportion congruenceG, over(faminc_3)


**TABLE 5:
***ACA repeal - simple conflict districts
*MODEL 1: vote_v2*income 
estimates clear
logit H_acarepeal1 vote_v2##copartisan c.cent_log_income##copartisan if nconflictvote_v2G==1 [pweight=V103], cluster(st_dist)
eststo
/*Figure2:
margins, at(cent_log_income=(-1.5(.5)1.5) copartisan=(0 1))
marginsplot, ytitle("Pr(Congruence)") xtitle("Centered Log of Income")  ///
       legend(row(1) order(1 "Not Copartisan" 2 "Is Copartisan" ))*/
*MODEL 2: All pol activities & income 
logit H_acarepeal1 vote_v2##copartisan polact3##copartisan donate##copartisan ///
   c.cent_log_income##copartisan if nconflictvote_v2G==1 [pweight=V103], cluster(st_dist)
eststo
*MODEL 3: All pol activities & income with controls
logit H_acarepeal1 vote_v2##copartisan polact3##copartisan donate##copartisan ///
   c.cent_log_income##copartisan educ age gender i.pid_r afam hisp other   ///
   if nconflictvote_v2G==1 [pweight=V103], cluster(st_dist)	   
eststo
/*Figure 3
margins, at(cent_log_income=(-1.5(.5)1.5) copartisan=1 vote_v2=1 donate=(0) polact3=(0)) ///
	at(cent_log_income=(-1.5(.5)1.5) copartisan=1 vote_v2=1 donate=(1) polact3=(1)) noatlegend
marginsplot, recast(line) recastci(rarea) legend(row(1) order(1 "No Alternative Behaviors" 2 "All Alternative Behaviors" )) ///
	ytitle("Pr(Congruence)") xtitle("Centered Log of Income") */
esttab using Table5.rtf, b(3) se(3) ar2 label title (Repeal Affordable Care Act) ///
		drop(0.vote_v2 0.copartisan 0.vote_v2#0.copartisan 0.vote_v2#1.copartisan 1.vote_v2#0.copartisan ///
	     0.polact3 0.polact3#0.copartisan 0.polact3#1.copartisan 1.polact3#0.copartisan ///
		 0.donate 0.donate#0.copartisan 0.donate#1.copartisan 1.donate#0.copartisan) ///
		 replace

***TABLE 6
egen add_indx_all = rowtotal(polact3 vote_v2 donate)
label var add_indx_all "Additive Index of Three Activity Types"

*Activities index
eststo clear
logit H_acarepeal1 i.add_indx_all if nconflictvote_v2G==1 [pweight=V103], cluster(st_dist)
eststo
*Activities and copartisan
logit H_acarepeal1 i.add_indx_all i.copartisan if nconflictvote_v2G==1 [pweight=V103], cluster(st_dist)
eststo
*Activities, copartisan and income
logit H_acarepeal1 i.add_indx_all i.copartisan c.cent_log_income if nconflictvote_v2G==1 [pweight=V103], cluster(st_dist)
eststo
*Activities, copartisan and income with interaction terms
logit H_acarepeal1 i.add_indx_all##c.cent_log_income i.add_indx_all##i.copartisan i.copartisan##c.cent_log_income  if nconflictvote_v2G==1 [pweight=V103], cluster(st_dist)
eststo
esttab using Table6.rtf, b(3) se(3) ar2 label title (ACA Participation Index)


		 

*****************
*****FIGURES*****
*****************

*FIGURE 1A, BASED ON TABLE2 MODEL2
logit H_acarepeal1 vote_v2##copartisan if nconflictvote_v2G==1 [pweight=V103], cluster(st_dist)
margins vote_v2##copartisan
marginsplot, ytitle("Pr(Congruence)")
*Fig1A_Voting

*FIGURE 1B, BASED ON TABLE3 MODEL2
logit H_acarepeal1 donate##copartisan if nconflictdonateG==1 [pweight=V103], cluster(st_dist)
margins donate##copartisan
marginsplot, ytitle("Pr(Congruence)")
*Fig1B_Donate

*FIGURE 1C, BASED ON TABLE3 MODEL4
lab values polact3 vote_
logit H_acarepeal1 polact3##copartisan if nconflictpolact3G==1 [pweight=V103], cluster(st_dist)
margins polact3##copartisan
marginsplot, ytitle("Pr(Congruence)")
*Fig1C_Other activities

*FIGURE 2
logit H_acarepeal1 vote_v2##copartisan c.cent_log_income##copartisan if nconflictvote_v2G==1 [pweight=V103], cluster(st_dist)
margins, at(cent_log_income=(-1.5(.5)1.5) copartisan=(0 1))
marginsplot, ytitle("Pr(Congruence)") xtitle("Centered Log of Income")  ///
       legend(row(1) order(3 "Not Copartisan" 4 "Is Copartisan" ))

*FIGURE 3
logit H_acarepeal1 vote_v2##copartisan polact3##copartisan donate##copartisan ///
   c.cent_log_income##copartisan educ age gender i.pid_r afam hisp other   ///
   if nconflictvote_v2G==1 [pweight=V103], cluster(st_dist)	   
margins, at(cent_log_income=(-1.5(.5)1.5) copartisan=1 vote_v2=1 donate=(0) polact3=(0)) ///
	at(cent_log_income=(-1.5(.5)1.5) copartisan=1 vote_v2=1 donate=(1) polact3=(1)) noatlegend
marginsplot, recast(line) recastci(rarea) legend(row(1) order(3 "No Alternative Behaviors" 4 "All Alternative Behaviors" )) ///
	ytitle("Pr(Congruence)") xtitle("Centered Log of Income") 

*FIGURE 4 - PARTICIPATION INDEX
logit H_acarepeal1 i.add_indx_all##c.cent_log_income i.add_indx_all##i.copartisan i.copartisan##c.cent_log_income  if nconflictvote_v2G==1 [pweight=V103], cluster(st_dist)
*Fig 4A
margins add_indx_all, at(cent_log_income=(-1.5(.5)1.5) copartisan=(1))
marginsplot, legend(size(small) row(2) order(5 "No Behaviors" 6 "1 Behavior" 7 "2 Behaviors" 8 "3 Behaviors")) ///
		ytitle("Pr(Congruence)") xtitle("Centered Log of Income") title(Probability of Congruence for Co-partisans) 
*Fig 4B
margins add_indx_all, at(cent_log_income=(-1.5(.5)1.5) copartisan=(0)) 
marginsplot, legend(size(small) row(2) order(5 "No Behaviors" 6 "1 Behavior" 7 "2 Behaviors" 8 "3 Behaviors")) ///
	ytitle("Pr(Congruence)") xtitle("Centered Log of Income") title(Probability of Congruence for Non-co-partisans) 

		
***************
*APPENDIX - win ratio analyses
***************
egen win4_ratio=rowtotal(H_koreafta H_acarepeal1 H_keystone H_dontask)
replace win4_ratio = 100*(win4_ratio/4)
label var win4_ratio "Win Ratio 4 issues"

*Retaining conflict districts
local activities "polact3 vote_v2 donate"
foreach l of local activities {
	gen allconflict4_combined_`l' = nconflict`l'F | nconflict`l'G | nconflict`l'H | nconflict`l'J
	label var allconflict4_combined_`l' "All Conflict Districts Across all Issue Types: `l'"
	label val allconflict4_combined_`l' conf
}

* Check Ns.
set more off
local policies "polact3 vote_v2 donate"
foreach l of local policies {
	tab1 allconflict4_combined_`l' 
}



*Descriptives check
*vote: 
tab allconflict4_combined_vote_v2, miss /*78.3%*/
*donate: 
tab allconflict4_combined_donate, miss /*74.8%*/
*polact3: 
tab allconflict4_combined_polact3, miss /*78.5%*/
*Only districts that have conflict on vote, donate & polact3
gen allconflict4_all = allconflict4_combined_vote_v2==1 & allconflict4_combined_donate==1 & allconflict4_combined_polact3==1
tab allconflict4_all, miss /*55.8%*/

*WIN RATIO TABLE, 4 ISSUES 
eststo clear
*Vote general
reg win4_ratio vote_v2 if allconflict4_all==1 [pweight=V103], cluster(st_dist)
eststo
reg win4_ratio vote_v2##copartisan if allconflict4_all==1 [pweight=V103], cluster(st_dist)
eststo
*Donate
reg win4_ratio donate if allconflict4_all==1 [pweight=V103], cluster(st_dist)
eststo
reg win4_ratio donate##copartisan if allconflict4_all==1 [pweight=V103], cluster(st_dist)
eststo
*Activities
reg win4_ratio polact3 if allconflict4_all==1 [pweight=V103], cluster(st_dist)
eststo
reg win4_ratio polact3##copartisan if allconflict4_all==1 [pweight=V103], cluster(st_dist)
eststo
esttab using win4ratio_appendix.rtf, b(3) se(3) ar2 label title (By Activity) ///
	drop(0.vote_v2 0.copartisan 0.vote_v2#0.copartisan 0.vote_v2#1.copartisan 1.vote_v2#0.copartisan ///
	0.donate 0.copartisan 0.donate#0.copartisan 0.donate#1.copartisan 1.donate#0.copartisan ///
	0.polact3 0.copartisan 0.polact3#0.copartisan 0.polact3#1.copartisan 1.polact3#0.copartisan) ///
	replace

*/
